package web.fabrimind.qc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.qc.domain.QualityInspection;
import web.fabrimind.qc.service.IQualityInspectionService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;

/**
 * 质量检验Controller
 * 
 * @author ruoyi
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/qc/inspection")
public class QualityInspectionController extends BaseController
{
    @Autowired
    private IQualityInspectionService qualityInspectionService;

    /**
     * 查询质量检验列表
     */
    @PreAuthorize("@ss.hasPermi('qc:inspection:list')")
    @GetMapping("/list")
    public TableDataInfo list(QualityInspection qualityInspection)
    {
        startPage();
        List<QualityInspection> list = qualityInspectionService.selectQualityInspectionList(qualityInspection);
        return getDataTable(list);
    }

    /**
     * 导出质量检验列表
     */
    @PreAuthorize("@ss.hasPermi('qc:inspection:export')")
    @Log(title = "质量检验", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualityInspection qualityInspection)
    {
        List<QualityInspection> list = qualityInspectionService.selectQualityInspectionList(qualityInspection);
        ExcelUtil<QualityInspection> util = new ExcelUtil<QualityInspection>(QualityInspection.class);
        util.exportExcel(response, list, "质量检验数据");
    }

    /**
     * 获取质量检验详细信息
     */
    @PreAuthorize("@ss.hasPermi('qc:inspection:query')")
    @GetMapping(value = "/{inspectionId}")
    public AjaxResult getInfo(@PathVariable("inspectionId") Long inspectionId)
    {
        return success(qualityInspectionService.selectQualityInspectionByInspectionId(inspectionId));
    }

    /**
     * 新增质量检验
     */
    @PreAuthorize("@ss.hasPermi('qc:inspection:add')")
    @Log(title = "质量检验", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QualityInspection qualityInspection)
    {
        return toAjax(qualityInspectionService.insertQualityInspection(qualityInspection));
    }

    /**
     * 修改质量检验
     */
    @PreAuthorize("@ss.hasPermi('qc:inspection:edit')")
    @Log(title = "质量检验", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualityInspection qualityInspection)
    {
        return toAjax(qualityInspectionService.updateQualityInspection(qualityInspection));
    }

    /**
     * 删除质量检验
     */
    @PreAuthorize("@ss.hasPermi('qc:inspection:remove')")
    @Log(title = "质量检验", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inspectionIds}")
    public AjaxResult remove(@PathVariable Long[] inspectionIds)
    {
        return toAjax(qualityInspectionService.deleteQualityInspectionByInspectionIds(inspectionIds));
    }
}
